package com.dst.java_demo.controller;

import com.dst.java_demo.exception.ServerException;
import com.dst.java_demo.mapper.TDemoMapper;
import com.dst.java_demo.model.entity.TDemo;
import com.dst.java_demo.model.request.DemoReq;
import com.dst.java_demo.util.ResponseDataUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LiJian
 * @date 2021/5/25
 */
@Controller
@RequestMapping(value = "/demo",produces = "application/json;charset=UTF-8")
public class DemoController {
    @Autowired
    private TDemoMapper tDemoMapper;

    @RequestMapping("/insert")
    @ResponseBody
    public String  demoInsert(@RequestBody DemoReq demoReq){
        return tDemoMapper.insert(TDemo.builder().name(demoReq.getName()).build())>0?"success":"fail";
    }
    @RequestMapping("/list")
    @ResponseBody
    public String list(@RequestParam Integer id){
        if(id==1){
            throw new ServerException(9999);
        }
        return ResponseDataUtil.returnResult(tDemoMapper.selectAll());
    }

}
